package com.alks.common.utils.excelUtils.nestExcel.handler;

import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.Head;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.write.handler.CellWriteHandler;
import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
import com.alks.common.utils.excelUtils.nestExcel.entity.ExportEntity;
import com.alks.common.utils.excelUtils.nestExcel.entity.ExportParam;
import org.apache.poi.ss.usermodel.*;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author: chen
 * @date: 2024/11/14
 * @description: 处理导出单元格
 */
public class CellHandler implements CellWriteHandler {

    private ExportEntity exportEntity;
    private List<List<String>> dataList;


    public CellHandler(ExportEntity exportEntity) {
        this.exportEntity = exportEntity;
    }
    public CellHandler(List<List<String>> dataList) {
        this.dataList = dataList;
    }

    /**
     * 居中
     */
    @Override
    public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell, Head head, Integer relativeRowIndex, Boolean isHead) {
        Workbook workbook = writeSheetHolder.getSheet().getWorkbook();
        CellStyle cellStyle = workbook.createCellStyle();
        cellStyle.setAlignment(HorizontalAlignment.CENTER);
        cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        //单元格边框
        cellStyle.setBorderTop(BorderStyle.THIN);
        cellStyle.setBorderBottom(BorderStyle.THIN);
        cellStyle.setBorderLeft(BorderStyle.THIN);
        cellStyle.setBorderRight(BorderStyle.THIN);
        cell.setCellStyle(cellStyle);
    }
}
